package ar.edu.unlp.info.tesis.database.service;

import java.util.List;

import ar.edu.unlp.info.tesis.domain.Actor;
import ar.edu.unlp.info.tesis.domain.Agent;
import ar.edu.unlp.info.tesis.domain.Group;


public class ActorService extends GenericService {

	public ActorService()
	{
		this.setClazz(Actor.class);
	}

	public void addAgentToGroup(String idGroup, String idAgent)
	{
		Agent agent = (Agent) this.getById(idAgent);
		Group group = (Group) this.getById(idGroup);
		
		if(!group.getMembers().contains(agent))
		{
			group.getMembers().add(agent);
			this.save(group);
		}
	}
	
	public void removeAgentFromGroup(String idGroup, String idAgent)
	{
		Agent agent = (Agent) this.getById(idAgent);
		Group group = (Group) this.getById(idGroup);
		
		if(group.getMembers().contains(agent))
		{
			group.getMembers().remove(agent);
			this.save(group);
		}
	}

	public List<Group> getGroups(String idAgent)
	{
		GenericService groupService = GenericService.getService(Group.class);
		groupService.addAlias("members", "memebersAlias");
		groupService.addEqualRestriction("memebersAlias.id", idAgent, false);
		return groupService.getList();
	}
}
